#ifndef __ASSET_H__
#define __ASSET_H__

#include "type.h"
#include "utils.h"

class Return {
  public:
    Return() {}
    virtual ~Return() {}
  private:
    float _mean;
    float _volatility;
};

class Asset {
  public:
    Asset() {

    }

    Asset(const std::string& n, float weight, float mi, float ma) : name(n),
      weight(weight),
      min(mi),
      max(ma) {

    }

    virtual ~Asset() {

    }

  public:
    void setup() {
      // format the raw data and store to price vector
    }

    void sampling(float m, float s) {
      mean = m;
      std = s;
    }

    void covariance() {
      if (coefficients.size() == 0) {
        return;
      }

      std::map<std::string, float>::iterator iter1;
      std::map<std::string, Asset*>::iterator iter2;
      for (iter1 = coefficients.begin(), iter2 = assets.begin(); iter1 != coefficients.end() && iter2 != assets.end(); ++iter1, ++iter2)
      {
        std::string n = iter1->first;
        float cf = iter1->second;
        Asset* as = iter2->second;
        float cv = cf * std * as->std;

        //std::cout<<"Calculate "<<name<<"("<<std<<") and "<<n<<"("<<as->std<<"): with covariance ("<<cv<<"), coefficient ("<<cf<<")"<<std::endl;
        covariances.insert(std::pair<std::string, float>(n, cv));
      }
    }

    void coefficient(const std::map<std::string, float>& coef) {
      coefficients = coef;
    }

    void print() {
      std::cout<<name<<": "<<std::endl;
      std::cout<<"\t"<<"Weight: "<<weight<<std::endl;
      std::cout<<"\t"<<"Mean: "<<mean<<std::endl;
      std::cout<<"\t"<<"Std: "<<std<<std::endl;

      std::map<std::string, float>::iterator iter;
      for (iter = covariances.begin(); iter != covariances.end(); ++iter)
      {
        std::string n = iter->first;
        float cv = iter->second;

        std::cout<<"\t"<<n<<": "<<cv<<std::endl;
      }

    }
  public:
    std::map<std::string, Asset*> assets;
    std::string name;
    float weight;
    float mean;
    float std;
    float min;
    float max;

    std::map<std::string, float> covariances;
    std::map<std::string, float> coefficients;
  private:
    std::map<std::string, float> _price;
};

#endif // asset.h
